<template>
  <div v-loading="isLoading" class="list-table companyNews" style="height: 98%;">
    <div id="d-scroll" class="infinite-list-wrapper infiniteActTask">
      <ul
        v-infinite-scroll="load"
        class="list company-news-item"
        :infinite-scroll-disabled="disabled"
      >
        <li v-for="(item, index) in List" :key="index" class="list-item">
          <div class="company-news-content">
            <div class="name" @click="openNews(item)">{{ item.newTitle }}</div>
            <div v-if="item.abstracts" class="abstracts">{{ item.abstracts }}</div>
            <div class="infos">
              <router-link
                target="_blank"
                :to="{path:'/company/base/companyBaseHome',query:{companyId: item.companyId}}"
                class="link_a dealName"
                style="max-width: 200px;overflow: hidden;text-overflow: ellipsis;"
              >{{ item.companyName }}</router-link>
              <span v-if="item.newSource" class="source" style="margin-left: 10px;">{{ item.newSource }}</span>
              <span v-if="item.newTime" class="time">{{ parseTime(item.newTime) }}</span>
            </div>
          </div>
        </li>
      </ul>
      <p>{{ loadTit }}</p>
      <div v-if="emptyIcon" class="noneData" style="height: auto;">
        <div>
          <svg-icon icon-class="none" class-name="none-icon" />
          <p>{{ $t('暂无数据') }}</p>
        </div>
      </div>
    </div>
  </div></template>
<script>
import { listCompanyNews } from '@/api/company/news/companyNews'
export default {
  name: 'News',
  data() {
    return {
      isLoading: true,
      loading: false,
      emptyIcon: false,
      List: [],
      total: 0,
      // 新闻信息表格数据
      companyNewsList: [],
      // 查询参数
      queryParams: {
        companyId: undefined,
        newTitle: undefined,
        newSource: undefined,
        newTime: undefined,
        pageNum: 0,
        pageSize: 30
      },
      loadTit: this.$t('加载中...')
    }
  },
  computed: {
    disabled() {
      return this.loading
    }
  },
  mounted() {},
  methods: {
    load() {
      this.queryParams.pageNum++
      this.getList(true)
    },
    /** 查询待办列表 */
    getList(flag) {
      this.isLoading = true
      this.emptyIcon = false
      this.loadTit = this.$t('加载中...')
      listCompanyNews(this.queryParams).then((response) => {
        if (response.code === 200 && flag) {
          this.List = this.List.concat(response.rows)
          // 多次加载数据
          if (this.List.length >= response.total && response.total !== 0) {
            this.loadTit = this.$t('没有更多了')
            this.loading = true
          }
          if (response.total === 0) {
            this.loadTit = ''
            this.emptyIcon = true
            this.isLoading = false
          }
          this.isLoading = false
        } else {
          // 第一次加载
          this.List = response.rows
          this.total = response.total
          this.isLoading = false
        }
      })
    },
    openNews(row) {
      if (row.newUrl.indexOf('http://') !== -1) {
        window.open(row.newUrl)
      } else if (row.newUrl.indexOf('https://') !== -1) {
        window.open(row.newUrl)
      } else {
        window.open('http://' + row.newUrl)
      }
    }
  }
}
</script>
